package com.example.lenovo_.myutils;

import android.content.Context;
import android.content.SharedPreferences;

public class SharedPfUtils {
	//SharedPreferences是Android平台上一个轻量级的存储类，主要是保存一些常用的配置比如窗口状态，一般在Activity中 重载窗口状态
	private SharedPreferences sp;
	//SharedPreferences存储类写入的变量
	private SharedPreferences.Editor editor;

	// 保存用户信息的sp文件名
	public static final String SPFILEUSERINFO = "spuserinfo";

	public SharedPfUtils(Context context, String file) {
		sp = context.getSharedPreferences(file, context.MODE_PRIVATE);
		editor = sp.edit();
	}

	// 用户的id
	public void setId(int id) {
		editor.putInt("id", id);
		editor.commit();
	}

	public int getId() {
		return sp.getInt("id", 0);
	}

	// 用户名
	public String getName() {
		return sp.getString("name", "");
	}

	public void setName(String name) {
		editor.putString("name", name);
		editor.commit();
	}

	// 用户密码
	public void setPassword(String passwd) {
		editor.putString("password", passwd);
		editor.commit();
	}

	public String getPassword() {
		return sp.getString("password", "");
	}

	// 用户是否开店的标志
	public String getFlagShopOpen() {
		return sp.getString("flagshop", "");
	}

	public void setFlagShopOpen(String flag) {
		editor.putString("flagshop", flag);
		editor.commit();
	}

	// 头像链接
	public String getUserImgUrl() {
		return sp.getString("userimgurl", "");
	}

	public void setUserImgUrl(String flag) {
		editor.putString("userimgurl", flag);
		editor.commit();
	}

	// 用户的邮箱
	public String getEmail() {
		return sp.getString("email", "");
	}

	public void setEmail(String email) {
		editor.putString("email", email);
		editor.commit();
	}

	// 用户自己的头像
	public Integer getImg() {
		return sp.getInt("img", 0);
	}

	public void setImg(int i) {
		editor.putInt("img", i);
		editor.commit();
	}

	// 是否在后台运行标记
	public void setIsStart(boolean isStart) {
		editor.putBoolean("isStart", isStart);
		editor.commit();
	}

	public boolean getIsStart() {
		return sp.getBoolean("isStart", false);
	}

	// 是否第一次运行本应用
	public void setIsFirst(boolean isFirst) {
		editor.putBoolean("isFirst", isFirst);
		editor.commit();
	}

	public boolean getisFirst() {
		return sp.getBoolean("isFirst", true);
	}

	// 是否保存登录信息
	public void setIsKeepUser(boolean i) {
		editor.putBoolean("flag", i);
		editor.commit();
	}

	public boolean getIsKeepUser() {
		return sp.getBoolean("flag", false);
	}

	// 记录店铺创建的时间
	public void setShopCreatedTime(String shopCreatedTime) {
		editor.putString("shopCreatedTime", shopCreatedTime);
		editor.commit();
	}

	public String getShopCreatedTime() {
		return sp.getString("shopCreatedTime", "");
	}
}
